﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ThucThe;
using DieuKhien;

namespace GiaoDien
{
    public partial class QL_Tour_them : Form
    {

        public QL_Tour_them()
        {
            InitializeComponent();
        }

        private void btn_OK_Click(object sender, EventArgs e)
        {
            try
            {
                Tour_dieukhien tour_dk = new Tour_dieukhien();
                Tour_thucthe tour_tt = new Tour_thucthe();
                ChiTiet_Tour_DiaDanh t_dd_tt = new ChiTiet_Tour_DiaDanh();
                ChiTiet_Tour_KhachSan t_ks_tt = new ChiTiet_Tour_KhachSan();
                ChiTiet_Tour_NhaHang t_nh_tt = new ChiTiet_Tour_NhaHang();
                ChiTiet_Tour_VanTai t_vt_tt = new ChiTiet_Tour_VanTai();
                tour_tt.MaTour = cbo_maTour.Text.Trim();
                t_dd_tt.MaDiaDanh = int.Parse(cbo_DiaDanh.SelectedValue.ToString());
                MessageBox.Show(t_dd_tt.MaDiaDanh.ToString());
                t_nh_tt.MaNhaHang = int.Parse(cbo_nhaHang.SelectedValue.ToString());
                t_ks_tt.MaKhachSan = int.Parse(cbo_khachSan.SelectedValue.ToString());
                t_vt_tt.MaVanTai = int.Parse(cbo_vanTai.SelectedValue.ToString());
                tour_tt.MoTa = txt_moTa.Text.Trim();
                tour_tt.LoaiHinh = cbo_loaiHinh.Text.Trim();
                tour_tt.NoiKhoiHanh = txt_noiKoiHanh.Text.Trim();
                tour_tt.TenTour = txt_tenTour.Text.Trim();
                tour_tt.GiaCa = long.Parse(txt_giaCa.Text.Trim());

                tour_dk.themTour(tour_tt, t_dd_tt, t_ks_tt, t_nh_tt, t_vt_tt);
                MessageBox.Show("Thêm thành công.");
                this.Close();
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Nhập đầy đủ các trường.", "Thêm tour");
            }
            catch (FormatException)
            {
                MessageBox.Show("Nhập số cho trường giá cả");
            }
        }

        private void QL_Tour_them_Load(object sender, EventArgs e)
        {
            Tour_dieukhien tour_dk = new Tour_dieukhien();
            Tour_thucthe tour_tt = new Tour_thucthe();
            DiaDanh_dieukhien dd_dk = new DiaDanh_dieukhien();
            DiaDanh_thucthe dd_tt = new DiaDanh_thucthe();
            NhaHang_dieukhien nh_dk = new NhaHang_dieukhien();
            NhaHang_thucthe nh_tt = new NhaHang_thucthe();
            KhachSan_dieukhien ks_dk = new KhachSan_dieukhien();
            KhachSan_thucthe ks_tt = new KhachSan_thucthe();
            VanTai_dieukhien vt_dk = new VanTai_dieukhien();
            VanTai_thucthe vt_tt = new VanTai_thucthe();
            cbo_maTour.DataSource = tour_dk.danhSachTouronly();
            cbo_maTour.DisplayMember = "maTour";
            cbo_DiaDanh.DataSource = dd_dk.danhSachDiaDanh();
            cbo_DiaDanh.DisplayMember = "tenDiaDanh";
            cbo_DiaDanh.ValueMember = "maDiaDanh";
            cbo_khachSan.DataSource = ks_dk.danhSachKhachSan();
            cbo_khachSan.DisplayMember = "tenKhachSan";
            cbo_khachSan.ValueMember = "maKhachSan";
            cbo_nhaHang.DataSource = nh_dk.danhSachNhaHang();
            cbo_nhaHang.DisplayMember = "tenNhaHang";
            cbo_nhaHang.ValueMember = "maNhaHang";
            cbo_vanTai.DataSource = vt_dk.danhSachVanTai();
            cbo_vanTai.DisplayMember = "tenVanTai";
            cbo_vanTai.ValueMember = "maVanTai";
        }

        private void btn_exit_Click(object sender, EventArgs e)
        {
            this.Close();
            QL ql = new QL();
            ql.Show();
        }
    }
}
